﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Things.ThingsWeb;
using Things.Common;

namespace Things.Web.GoodsOrders
{
    public partial class ViewOrder : Things.ThingsWeb.PageUtility
    {        
        public Guid GoodsOrderID
        {
            get
            {
                Guid guid = Guid.Empty;

                if (Request.Params["ID"] != null && Request.Params["ID"].Trim() != "")
                {
                    if (Guid.TryParse(Request.Params["ID"].Trim(), out guid) == true)
                    {
                    }
                    else
                    {
                        guid = Guid.Empty;
                    }
                }

                return guid;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            Things.Model.Buyer buyer = GetCurrentBuyer();
            if (buyer == null)
            {
                Session[ConstantString.SessionSourceURL] = Context.Request.Url;
                Response.Redirect(ConstantString.LoginPageURL);
            }

            if (!IsPostBack)
            {
                Things.BLL.GoodsOrders goBLL = new BLL.GoodsOrders();
                Things.Model.GoodsOrders goModel = goBLL.GetModel(GoodsOrderID);
                if (goModel != null && goModel.BuyerAccount==buyer.Account)
                {
                    // 快递
                    KuaiDiChaXun1.KuaiDiGongSi = goModel.KuaiDiGongSi;
                    KuaiDiChaXun1.KuaiDiDanHao = goModel.KuaiDiDanHao;
                    
                    //
                    BindData(goModel);

                    // 商品清单
                    OrderGoodsList1.GoodsOrderID = GoodsOrderID;
                }
                else
                {

                }  
              
               

            }
        }

        protected void BindData(Things.Model.GoodsOrders goModel)
        {
            // 订单编号
            lblOrderNumber.Text = goModel.GoodsOrderNumber.ToString();

            // 收货人信息
            BindReceiver(goModel);

            // 发票信息
            BindFaPiaoXinXi(goModel);

        }

        protected void BindReceiver(Things.Model.GoodsOrders goModel)
        {
            try
            {
                string[] infos = goModel.BuyerAddress.Split(new string[] { ", " }, StringSplitOptions.None);
                lblReceiver.Text = infos[0];
                lblAddress.Text = infos[1] + " " + infos[2];
                lblPostNumber.Text = infos[3];
                lblMobilePhone.Text = infos[4];
                lblTelPhone.Text = infos[5];
            }
            catch
            {
            }
        }

        protected void BindFaPiaoXinXi(Things.Model.GoodsOrders goModel)
        {
            try
            {
                string[] infos = goModel.FaPiaoXinXi.Split(new string[] { ", " }, StringSplitOptions.None);
                lblFaPiaoLeiXing.Text = infos[0];
                lblFaPiaoTaiTou.Text = infos[1];
                lblFaPiaoNeiRong.Text = infos[2];
            }
            catch
            {
            }
        }

    }
}